package eu.vranckaert.workRegistrationWidget.dao.util;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import eu.vranckaert.workRegistrationWidget.dao.helper.MySQLiteOpenHelper;

public class DaoHelperImpl implements DaoHelper {
    private Context ctx;
    private MySQLiteOpenHelper dbHelper;
    public SQLiteDatabase db;
    public Cursor cursor;

    public void openForWrite(Context ctx) throws SQLException {
        this.ctx = ctx;
        this.dbHelper = new MySQLiteOpenHelper(ctx);
        this.db = this.dbHelper.getWritableDatabase();
    }

    public void openForRead(Context ctx) throws SQLException {
        this.ctx = ctx;
        this.dbHelper = new MySQLiteOpenHelper(ctx);
        this.db = this.dbHelper.getReadableDatabase();
    }

    public void close() {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }

        this.dbHelper.close();
        this.db = null;
    }
}
